﻿Imports System.Reflection
Imports System.Reflection.Emit
Imports VBParser
Imports NotBasic.Compiler.Semantic

Namespace Compiler

    ''' <summary>
    ''' Provides special types such as <c>Object</c> or <c>String</c>
    ''' </summary>
    Public Class SpecialTypeProvider

        Public Sub New(ByVal referenceManager As ReferenceManager)
            Debug.Assert(referenceManager IsNot Nothing)

            Dim mscorlib As ReferencedAssembly = referenceManager.Mscorlib

            If mscorlib Is Nothing Then
                Throw New ArgumentException("The required assembly 'mscorlib' is not referenced.")
            End If
            'Start fill types
            With mscorlib.Assembly
                'reference types
                Me.Object = New ExternalTypeReference(.GetType("System.Object"))
                Me.String = New ExternalTypeReference(.GetType("System.String"))

                'integers
                Me.Int32 = New ExternalTypeReference(.GetType("System.Int32"))
                Me.Int16 = New ExternalTypeReference(.GetType("System.Int16"))
                Me.Int64 = New ExternalTypeReference(.GetType("System.Int64"))
                Me.Byte = New ExternalTypeReference(.GetType("System.Byte"))
                Me.UInt32 = New ExternalTypeReference(.GetType("System.UInt32"))
                Me.UInt16 = New ExternalTypeReference(.GetType("System.UInt16"))
                Me.UInt64 = New ExternalTypeReference(.GetType("System.UInt64"))
                Me.SByte = New ExternalTypeReference(.GetType("System.SByte"))

                'floats
                Me.Single = New ExternalTypeReference(.GetType("System.Single"))
                Me.Double = New ExternalTypeReference(.GetType("System.Double"))
                Me.Decimal = New ExternalTypeReference(.GetType("System.Decimal"))

                'special
                Me.DateTime = New ExternalTypeReference(.GetType("System.DateTime"))
                Me.Boolean = New ExternalTypeReference(.GetType("System.Boolean"))
            End With
        End Sub

        Public ReadOnly [Object] As TypeReference
        Public ReadOnly [String] As TypeReference
        Public ReadOnly Int32 As TypeReference
        Public ReadOnly Int16 As TypeReference
        Public ReadOnly Int64 As TypeReference
        Public ReadOnly [Byte] As TypeReference
        Public ReadOnly [Char] As TypeReference
        Public ReadOnly [Single] As TypeReference
        Public ReadOnly [Double] As TypeReference
        Public ReadOnly [Decimal] As TypeReference
        Public ReadOnly DateTime As TypeReference
        Public ReadOnly UInt32 As TypeReference
        Public ReadOnly UInt16 As TypeReference
        Public ReadOnly UInt64 As TypeReference
        Public ReadOnly [SByte] As TypeReference
        Public ReadOnly [Boolean] As TypeReference
    End Class
End Namespace